package com.xuhuan.demo.principle.inversion;

/**
 * @author huan.xu
 * @date 2021/10/1 18:51
 * @description 依赖倒置原则
 * 案例：接收消息
 */
public class DependecyInversion {

    public static void main(String[] args) {
        Persion persion = new Persion();
        String eamilInfo = persion.receiver(new Email());
        System.out.println(eamilInfo);
        String weiXinInfo = persion.receiver(new WeiXin());
        System.out.println(weiXinInfo);
    }
}

interface IReceiver {
    public String getInfo();
}

class Persion {
    public String receiver(IReceiver receiver) {
        return receiver.getInfo();
    }
}

class Email implements IReceiver {
    @Override
    public String getInfo() {
        return "邮件信息";
    }
}

class WeiXin implements IReceiver {

    @Override
    public String getInfo() {
        return "微信信息";
    }
}